<?php
/* SVN FILE: $Id: pages_controller.php 4407 2007-02-02 10:39:45Z phpnut $ */

/**
 * Short description for file.
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP versions 4 and 5
 *
 * CakePHP(tm) :  Rapid Development Framework <http://www.cakephp.org/>
 * Copyright 2005-2007, Cake Software Foundation, Inc.
 *								1785 E. Sahara Avenue, Suite 490-204
 *								Las Vegas, Nevada 89104
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright		Copyright 2005-2007, Cake Software Foundation, Inc.
 * @link				http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
 * @package			cake
 * @subpackage		cake.cake.libs.controller
 * @since			CakePHP(tm) v 0.2.9
 * @version			$Revision: 4407 $
 * @modifiedby		$LastChangedBy: phpnut $
 * @lastmodified	$Date: 2007-02-02 10:39:45 +0000 (Fri, 02 Feb 2007) $
 * @license			http://www.opensource.org/licenses/mit-license.php The MIT License
 */

/**
 * Short description for class.
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package		webrocket
 * @subpackage	webrocket.app.controllers.pages
 */
class PagesController extends AppController{

/**
 * Enter description here...
 *
 * @var unknown_type
 */
	 var $name = 'Pages';
	 var $uses = array('Page','Copyright','Subject');

/**
 * Displays a view
 *
 */
	function view($url)
	{
		$page = $this->Page->findByUrl($url);
		$this->set('page', $page);
	}
	 
	 
	 function admin_index()
	 {
	 	$this->set('pages', $this->Page->findAll());
	 }
/**
 *	Add a page
 *
 */
 	function admin_add()
	{
		$copyright_type = $this->Copyright->generateList();
		$this->set(compact('copyright_type'));
		
		$this->set('author_id', $this->othAuth->user('id'));
		$subject = $this->Page->Subject->generateList();
		$this->set(compact('subject'));
		
		if (isset($this->data))
		{
			if ($this->Page->save($this->data))
			{
				$this->Session->setFlash('Page successfuly created');
				$this->redirect('/pages/view/' . $this->Page->data['url']);
			}
		} else {
			$this->set('author_id', $this->othAuth->user('id'));
		}	
	}
	
	function admin_edit($id)
	{
		if (isset($this->data))
		{
			if ($this->Page->save($this->data))
			{
				$this->Session->setFlash('Page successfuly updated');
				$this->redirect('/pages/view/' . $this->Page->data['url']);
			}
		} else {
			$this->Page->id = $id;
        	$this->data = $this->Page->read();
		}
	}
	
	function admin_delete($id)
	{
		if ($this->Page->delete($id))
		{
			$this->Session->setFlash('Page Removed');
			$this->redirect('/admin/pages/');
		}
	}
}
?>